package com.usian.controller;

import com.usian.pojo.Etc;
import com.usian.service.EtcService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/etc")
public class EtcController {
    @Autowired
    private EtcService etcService;
    @RequestMapping("findAll")
    public String findAll(Model model){
        List<Etc>etcList=etcService.findAll();
        model.addAttribute("etcList",etcList);
        return "index";
    }
    @RequestMapping("selectAll")
    public String selectAll(Model model){
        List<Etc>etcList=etcService.select();
        model.addAttribute("etcList",etcList);
        return "indexEtc";
    }
    @RequestMapping("findName")
    public String selectAll(Model model,Etc etc){
        List<Etc>etcList=etcService.findName(etc);
        model.addAttribute("etcList",etcList);
        return "index";
    }
    @RequestMapping("findName2")
    public String selectAll2(Model model,Etc etc){
        List<Etc>etcList=etcService.findName2(etc);
        model.addAttribute("etcList",etcList);
        return "indexEtc";
    }
    @RequestMapping("toInsert")
    public String toInsert(){
        return "addEtc";
    }
    @RequestMapping("insertEtc")
    public String insertStudent(Etc etc){
        etcService.add(etc);
        return "redirect:/etc/findAll";
    }
    @RequestMapping("findById")
    public String updateEtc(Integer id,Model model){
        Etc etc=etcService.findById(id);
        model.addAttribute("etc",etc);
        return "updateEct";
    }
    @RequestMapping("update")
    public String update(Etc etc){
        etcService.update(etc);
        return "redirect:/etc/findAll";
    }
    @RequestMapping("delete")
    public String delete(Integer id){
        etcService.delete(id);
        return "redirect:/etc/findAll";
    }
}
